<template>
  <div class="app-container">
    <el-tabs v-model="activeName"  @tab-click="handleClick">
      <el-tab-pane label="简体" name="114"></el-tab-pane>
      <el-tab-pane label="繁体" name="116"></el-tab-pane>
      <el-tab-pane label="English" name="115"></el-tab-pane>
    </el-tabs>
    <div class="middle">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="图片" prop="imgUrl">
          <div style="font-size: 14px;color:#F56C6C;">建议尺寸774px X 434px</div>
          <ImageUpload v-model="form.imgUrl" :limit="1"></ImageUpload>
        </el-form-item>
      </el-form>
    </div>
    <div class="footerBtn">
      <el-button type="primary" style="width:200px" @click="submitForm">保 存</el-button>
    </div>
  </div>
</template>

<script>
import { getConfig, updateConfig } from "@/api/system/config";

export default {
  name: "contactUs",
  dicts: ['sys_lang'],
  data() {
    return {
      activeName: '114',
      info:{},
      // 表单参数
      form: {},
      // 表单校验
      rules: {

      }
    };
  },
  created() {
    this.getConfigKeyInfo();
  },
  methods: {
    getImagePath(val) {
      this.form.imgUrl = val
    },
    handleClick(tab, event) {
      this.getConfigKeyInfo();
    },
    getConfigKeyInfo(){
      getConfig(this.activeName).then(response => {
        console.log(response)
        this.info = response.data
        this.form = JSON.parse(this.info.configValue)
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(this.form)
          this.info.configValue = JSON.stringify(this.form)
          console.log(this.info.configValue, this.form)
          updateConfig(this.info).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.getConfigKeyInfo();
          });
        }
      });
    },
    
  }
};
</script>
<style scoped lang="scss">
.middle{
  padding: 50px 10% 0;
}
.footerBtn{
  display: flex;
  justify-content: center;
  margin-top: 50px;
}
</style>